package com.asdc.autoscanfiles.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
 * @Author zhangbingyue
 * @Description //TODO $ 数据拼接导入新的数据库
 * @Date $ $
 * @Param $
 * @return $
 **/
@RestController
@RequestMapping("/dataUtils")
public class DataUtilsController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @RequestMapping(value = "/start")
    @ResponseBody
    public String start() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("archive", insertTabArchive());
        map.put("volime", insertTabVolume());
        map.put("file", insertTabFile());
        map.put("archive2", insertTabArchive2());
        map.put("file2", insertTabFile2());
        map.put("file3", insertTabFile3());
        map.put("archive4", insertTabArchive4());
        map.put("file4", insertTabFile4());
        try {

            long begin = System.currentTimeMillis();
            final Semaphore semaphore = new Semaphore(8);
            ExecutorService executor = Executors.newCachedThreadPool();
            for (String s : map.keySet()) {
                executor.execute(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            semaphore.acquire();
                        } catch (InterruptedException e) {
                            try {
                                throw new Exception(e.getMessage().toString());
                            } catch (Exception e1) {
                                e1.printStackTrace();
                            }
                        }
                        //调用批量插入
                        beatchUpdate(s, map.get(s).toString());
                        //释放线程
                        semaphore.release();
                    }
                });
            }
            System.out.println("已经开启所有的子线程");
            executor.shutdown();
            System.out.println("shutdown()：启动一次顺序关闭，执行以前提交的任务，但不接受新任务。");
            while (true) {
                if (executor.isTerminated()) {
                    System.out.println("所有的子线程都结束了！");
                    imgInsert();
                    break;
                }
            }

            System.out.println("主方法耗时=" + (System.currentTimeMillis() - begin));

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.out.println("主方法结束");
        }

        return "执行成功！";
    }

    public void imgInsert() {
        long begin = System.currentTimeMillis();

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("65", "a_archive");
        map.put("66", "a_volume");
        map.put("67", "a_file");
        map.put("74", "a_archive_2");
        map.put("75", "a_file_2");
        map.put("76", "a_file_3");
        map.put("89", "a_archive_4");
        map.put("90", "a_file_4");

        final Semaphore semaphore = new Semaphore(5);
        ExecutorService executor = Executors.newCachedThreadPool();
        for (String s : map.keySet()) {
            final String s1 = insertImgFile(String.valueOf(map.get(s)), s);
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        semaphore.acquire();
                    } catch (InterruptedException e) {
                        try {
                            throw new Exception(e.getMessage().toString());
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                    //调用批量插入
                    beatchUpdate1("a_img_file", s1);
                    //释放线程
                    semaphore.release();
                }
            });
        }
        executor.shutdown();
        while (true) {
            if (executor.isTerminated()) {
                System.out.println("执行完成！插入图片耗时=" + (System.currentTimeMillis() - begin));
                break;
            }
        }
    }


    public void beatchUpdate(String tabName, String sqlRecordingLog) {
        KeyHolder keyHolder = new GeneratedKeyHolder();
        jdbcTemplate.update(new PreparedStatementCreator() {
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement(sqlRecordingLog, Statement.RETURN_GENERATED_KEYS);
                return ps;
            }
        }, keyHolder);

        int resultSize = keyHolder.getKeyList().size();
        System.out.println("插入成功" + tabName + "条数=" + resultSize);

//        int[] size=this.jdbcTemplate.batchUpdate(new String[]{sqlRecordingLog});
//        System.out.println("插入成功" + tabName + "条数=" + size[0]);

    }

    public void beatchUpdate1(String tabName, String sqlRecordingLog) {
        int i= jdbcTemplate.update(new PreparedStatementCreator() {
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement(sqlRecordingLog, Statement.RETURN_GENERATED_KEYS);
                return ps;
            }
        });
        System.out.println("插入成功" + tabName + "条数=" + i);
    }

    public String insertImgFile(String tabName, String libId) {
        String sql = "INSERT ignore INTO a_img_file (\n" +
                "	id,\n" +
                "	record_id,\n" +
                "	record_name,\n" +
                "	image_name,\n" +
                "	storage_dir\n" +
                ") SELECT\n" +
                "	i.id,\n" +
                "	i.data_record_id,\n" +
                "	'" + tabName + "' AS record_name,\n" +
                "	i.file_name,\n" +
                "	i.storage_dir\n" +
                "FROM\n" +
                "	d_attached_file_info i\n" +
//                "LEFT JOIN " + tabName + " a ON i.data_record_id = a.id\n" +
                "WHERE\n" +
                "	i.lib_id = '" + libId + "'";
        return sql;
    }

    public String insertTabArchive() {
        String sqlRecordingLog = "INSERT ignore INTO a_archive (\n" +
                "	id,\n" +
                "	station_id,\n" +
                "	fix_code,\n" +
                "	region,\n" +
                "	element,\n" +
                "	time_interval,\n" +
                "	data_items,\n" +
                "	img_dataset,\n" +
                "	station,\n" +
                "	years_month,\n" +
                "	img_order,\n" +
                "	suffix,\n" +
                "	observer,\n" +
                "	archive_no,\n" +
                "	archive_num,\n" +
                "	register_time,\n" +
                "	district_num,\n" +
                "	classify_num,\n" +
                "	order_num,\n" +
                "	archive_code,\n" +
                "	archive_name,\n" +
                "	theme_words,\n" +
                "	pro_unit,\n" +
                "	YEAR,\n" +
                "	numer,\n" +
                "	sec_class,\n" +
                "	publish_date,\n" +
                "	reten_period,\n" +
                "	loan,\n" +
                "	shelf_mark,\n" +
                "	change_content,\n" +
                "	digitalize_content,\n" +
                "	LEVEL,\n" +
                "	source,\n" +
                "	outlay,\n" +
                "	win_content,\n" +
                "	participant,\n" +
                "	remarks,\n" +
                "	archive_code1,\n" +
                "	volume_code,\n" +
                "	doc_code,\n" +
                "	file_name,\n" +
                "	formation_date,\n" +
                "	num_page\n" +
                ") SELECT\n" +
                "	id AS id,\n" +
                "	station_id AS station_id,\n" +
                "	text1 AS fix_code,\n" +
                "	text2 AS region,\n" +
                "	text3 AS element,\n" +
                "	text4 AS time_interval,\n" +
                "	text5 AS data_items,\n" +
                "	text6 AS img_dataset,\n" +
                "	text7 AS station,\n" +
                "	text8 AS years_month,\n" +
                "	text9 AS img_order,\n" +
                "	text10 AS suffix,\n" +
                "	text11 AS observer,\n" +
                "	text12 AS archive_no,\n" +
                "	text13 AS archive_num,\n" +
                "	text14 AS register_time,\n" +
                "	text15 AS district_num,\n" +
                "	text16 AS classify_num,\n" +
                "	text17 AS order_num,\n" +
                "	text18 AS archive_code,\n" +
                "	text19 AS archive_name,\n" +
                "	text20 AS theme_words,\n" +
                "	text21 AS pro_unit,\n" +
                "	text22 AS YEAR,\n" +
                "	text23 AS numer,\n" +
                "	text24 AS sec_class,\n" +
                "	text25 AS publish_date,\n" +
                "	text26 AS reten_period,\n" +
                "	text27 AS loan,\n" +
                "	text28 AS shelf_mark,\n" +
                "	text29 AS change_content,\n" +
                "	text30 AS digitalize_content,\n" +
                "	text31 AS LEVEL,\n" +
                "	text32 AS source,\n" +
                "	text33 AS outlay,\n" +
                "	text34 AS win_content,\n" +
                "	text35 AS participant,\n" +
                "	text36 AS remarks,\n" +
                "	text37 AS archive_code1,\n" +
                "	text38 AS volume_code,\n" +
                "	text39 AS doc_code,\n" +
                "	text40 AS file_name,\n" +
                "	text41 AS formation_date,\n" +
                "	text43 AS num_page\n" +
                "FROM\n" +
                "	d_files\n" +
                "WHERE\n" +
                "	lib_id = '65'";
        return sqlRecordingLog;
    }

    public String insertTabVolume() {
        String sqlRecordingLog = "INSERT ignore INTO a_volume (\n" +
                "	id,\n" +
                "	parent_id,\n" +
                "	fix_code,\n" +
                "	suffix,\n" +
                "	archive_no,\n" +
                "	archive_code1,\n" +
                "	archive_code,\n" +
                "	volume_code,\n" +
                "	doc_code,\n" +
                "	file_name,\n" +
                "	theme_words,\n" +
                "	pro_unit,\n" +
                "	formation_date,\n" +
                "	region,\n" +
                "	num_page,\n" +
                "	change_content,\n" +
                "	link_path,\n" +
                "	LEVEL,\n" +
                "	remarks,\n" +
                "	element,\n" +
                "	time_interval,\n" +
                "	data_items,\n" +
                "	img_dataset,\n" +
                "	station,\n" +
                "	years_month,\n" +
                "	img_order\n" +
                ") SELECT\n" +
                "	id AS id,\n" +
                "	parent_id AS parent_id,\n" +
                "	text1 AS fix_code,\n" +
                "	text10 AS suffix,\n" +
                "	text11 AS archive_no,\n" +
                "	text12 AS archive_code1,\n" +
                "	text13 AS archive_code,\n" +
                "	text14 AS volume_code,\n" +
                "	text15 AS doc_code,\n" +
                "	text16 AS file_name,\n" +
                "	text17 AS theme_words,\n" +
                "	text18 AS pro_unit,\n" +
                "	text19 AS formation_date,\n" +
                "	text2 AS region,\n" +
                "	text20 AS num_page,\n" +
                "	text21 AS change_content,\n" +
                "	text22 AS link_path,\n" +
                "	text23 AS LEVEL,\n" +
                "	text24 AS remarks,\n" +
                "	text3 AS element,\n" +
                "	text4 AS time_interval,\n" +
                "	text5 AS data_items,\n" +
                "	text6 AS img_dataset,\n" +
                "	text7 AS station,\n" +
                "	text8 AS years_month,\n" +
                "	text9 AS img_order\n" +
                "FROM\n" +
                "	d_archive\n" +
                "WHERE\n" +
                "	lib_id = '66'";
        return sqlRecordingLog;
    }

    public String insertTabFile() {
        String sqlRecordingLog = "INSERT ignore INTO a_file (\n" +
                "	id,\n" +
                "	parent_id,\n" +
                "	fix_code,\n" +
                "	region,\n" +
                "	element,\n" +
                "	time_interval,\n" +
                "	data_items,\n" +
                "	img_dataset,\n" +
                "	station,\n" +
                "	years_month,\n" +
                "	img_order,\n" +
                "	suffix,\n" +
                "	date_interval,\n" +
                "	sta_items,\n" +
                "	element1,\n" +
                "	element1_unit,\n" +
                "	element1_times,\n" +
                "	element1_items,\n" +
                "	element2,\n" +
                "	element2_unit,\n" +
                "	element2_times,\n" +
                "	element2_items,\n" +
                "	element3,\n" +
                "	element3_unit,\n" +
                "	element3_times,\n" +
                "	element3_items,\n" +
                "	element4,\n" +
                "	element4_unit,\n" +
                "	element4_times,\n" +
                "	element4_items,\n" +
                "	element5,\n" +
                "	element5_unit,\n" +
                "	element5_times,\n" +
                "	element5_items,\n" +
                "	element6,\n" +
                "	element6_unit,\n" +
                "	element6_times,\n" +
                "	element6_items,\n" +
                "	element19,\n" +
                "	element19_unit,\n" +
                "	element19_times,\n" +
                "	element19_items,\n" +
                "	element7,\n" +
                "	element7_unit,\n" +
                "	element7_times,\n" +
                "	element7_items,\n" +
                "	element8,\n" +
                "	element8_unit,\n" +
                "	element8_times,\n" +
                "	element8_items,\n" +
                "	element9,\n" +
                "	element9_unit,\n" +
                "	element9_times,\n" +
                "	element9_items,\n" +
                "	element10,\n" +
                "	element10_unit,\n" +
                "	element10_times,\n" +
                "	element10_items,\n" +
                "	element11,\n" +
                "	element11_unit,\n" +
                "	element11_times,\n" +
                "	element11_items,\n" +
                "	element12,\n" +
                "	element12_unit,\n" +
                "	element12_times,\n" +
                "	element12_items,\n" +
                "	element13,\n" +
                "	element13_unit,\n" +
                "	element13_times,\n" +
                "	element13_items,\n" +
                "	element14,\n" +
                "	element14_unit,\n" +
                "	element14_times,\n" +
                "	element14_items,\n" +
                "	element15,\n" +
                "	element15_unit,\n" +
                "	element15_times,\n" +
                "	element15_items,\n" +
                "	element16,\n" +
                "	element16_unit,\n" +
                "	element16_times,\n" +
                "	element16_items,\n" +
                "	element17,\n" +
                "	element17_unit,\n" +
                "	element17_times,\n" +
                "	times,\n" +
                "	element18,\n" +
                "	element18_unit,\n" +
                "	element18_times,\n" +
                "	element18_items,\n" +
                "	element17_items,\n" +
                "	element20,\n" +
                "	element20_unit,\n" +
                "	element20_times,\n" +
                "	element20_items,\n" +
                "	element21,\n" +
                "	element21_unit,\n" +
                "	element21_times,\n" +
                "	element21_items,\n" +
                "	element22,\n" +
                "	element22_unit,\n" +
                "	element22_times,\n" +
                "	element22_items,\n" +
                "	element23,\n" +
                "	element23_unit,\n" +
                "	element23_times,\n" +
                "	element23_items,\n" +
                "	element24,\n" +
                "	element24_unit,\n" +
                "	element24_times,\n" +
                "	element24_items,\n" +
                "	element25,\n" +
                "	element25_unit,\n" +
                "	element25_times,\n" +
                "	element25_items,\n" +
                "	element26,\n" +
                "	element26_unit,\n" +
                "	element26_times,\n" +
                "	element26_items,\n" +
                "	element27,\n" +
                "	element27_unit,\n" +
                "	element27_times,\n" +
                "	element27_items,\n" +
                "	element28,\n" +
                "	element28_unit,\n" +
                "	element28_times,\n" +
                "	element28_items,\n" +
                "	element29,\n" +
                "	element29_unit,\n" +
                "	element29_times,\n" +
                "	element29_items,\n" +
                "	archive_code\n" +
                ") SELECT\n" +
                "	id,\n" +
                "	parent_id,\n" +
                "	text1,\n" +
                "	text2,\n" +
                "	text3,\n" +
                "	text4,\n" +
                "	text5,\n" +
                "	text6,\n" +
                "	text7,\n" +
                "	text8,\n" +
                "	text9,\n" +
                "	text10,\n" +
                "	text11,\n" +
                "	text12,\n" +
                "	text13,\n" +
                "	text14,\n" +
                "	text15,\n" +
                "	text16,\n" +
                "	text17,\n" +
                "	text18,\n" +
                "	text19,\n" +
                "	text20,\n" +
                "	text21,\n" +
                "	text22,\n" +
                "	text23,\n" +
                "	text24,\n" +
                "	text25,\n" +
                "	text26,\n" +
                "	text27,\n" +
                "	text28,\n" +
                "	text29,\n" +
                "	text30,\n" +
                "	text31,\n" +
                "	text32,\n" +
                "	text33,\n" +
                "	text34,\n" +
                "	text35,\n" +
                "	text36,\n" +
                "	text37,\n" +
                "	text38,\n" +
                "	text39,\n" +
                "	text40,\n" +
                "	text41,\n" +
                "	text42,\n" +
                "	text43,\n" +
                "	text44,\n" +
                "	text45,\n" +
                "	text46,\n" +
                "	text47,\n" +
                "	text48,\n" +
                "	text49,\n" +
                "	text50,\n" +
                "	text51,\n" +
                "	text52,\n" +
                "	text53,\n" +
                "	text54,\n" +
                "	text55,\n" +
                "	text56,\n" +
                "	text57,\n" +
                "	text58,\n" +
                "	text59,\n" +
                "	text60,\n" +
                "	text61,\n" +
                "	text62,\n" +
                "	text63,\n" +
                "	text64,\n" +
                "	text65,\n" +
                "	text66,\n" +
                "	text67,\n" +
                "	text68,\n" +
                "	text69,\n" +
                "	text70,\n" +
                "	text71,\n" +
                "	text72,\n" +
                "	text73,\n" +
                "	text74,\n" +
                "	text75,\n" +
                "	text76,\n" +
                "	text77,\n" +
                "	text78,\n" +
                "	text79,\n" +
                "	text80,\n" +
                "	text81,\n" +
                "	text82,\n" +
                "	text83,\n" +
                "	text84,\n" +
                "	text85,\n" +
                "	text86,\n" +
                "	text87,\n" +
                "	text88,\n" +
                "	text89,\n" +
                "	text90,\n" +
                "	text91,\n" +
                "	text92,\n" +
                "	text93,\n" +
                "	text94,\n" +
                "	text95,\n" +
                "	text96,\n" +
                "	text97,\n" +
                "	text98,\n" +
                "	text99,\n" +
                "	text100,\n" +
                "	text101,\n" +
                "	text102,\n" +
                "	text103,\n" +
                "	text104,\n" +
                "	text105,\n" +
                "	text106,\n" +
                "	text107,\n" +
                "	text108,\n" +
                "	text109,\n" +
                "	text110,\n" +
                "	text111,\n" +
                "	text112,\n" +
                "	text113,\n" +
                "	text114,\n" +
                "	text115,\n" +
                "	text116,\n" +
                "	text117,\n" +
                "	text118,\n" +
                "	text119,\n" +
                "	text120,\n" +
                "	text121,\n" +
                "	text122,\n" +
                "	text123,\n" +
                "	text124,\n" +
                "	text125,\n" +
                "	text126,\n" +
                "	text127,\n" +
                "	text128,\n" +
                "	text129,\n" +
                "	text140\n" +
                "FROM\n" +
                "	d_text\n" +
                "WHERE\n" +
                "	lib_id = '67'";
        return sqlRecordingLog;
    }

    public String insertTabArchive2() {
        String sqlRecordingLog = "INSERT ignore INTO a_archive_2 (\n" +
                "	id,\n" +
                "	station_id,\n" +
                "	fix_code,\n" +
                "	region,\n" +
                "	element,\n" +
                "	time_interval,\n" +
                "	data_items,\n" +
                "	img_dataset,\n" +
                "	station,\n" +
                "	years_month,\n" +
                "	img_order,\n" +
                "	suffix,\n" +
                "	archive_no,\n" +
                "	archive_num,\n" +
                "	register_time,\n" +
                "	district_num,\n" +
                "	classify_num,\n" +
                "	order_num,\n" +
                "	archive_name,\n" +
                "	theme_words,\n" +
                "	pro_unit,\n" +
                "	YEAR,\n" +
                "	numer,\n" +
                "	sec_class,\n" +
                "	publish_date,\n" +
                "	reten_period,\n" +
                "	loan,\n" +
                "	shelf_mark,\n" +
                "	change_content,\n" +
                "	digitalize_content,\n" +
                "	LEVEL,\n" +
                "	source,\n" +
                "	outlay,\n" +
                "	win_content,\n" +
                "	participant,\n" +
                "	remarks,\n" +
                "	archive_code1,\n" +
                "	archive_code,\n" +
                "	volume_code,\n" +
                "	doc_code,\n" +
                "	file_name,\n" +
                "	formation_date,\n" +
                "	num_page,\n" +
                "	change_content1,\n" +
                "	link_path,\n" +
                "	level1,\n" +
                "	remarks1\n" +
                ") SELECT\n" +
                "	id,\n" +
                "	station_id,\n" +
                "	text1,\n" +
                "	text2,\n" +
                "	text3,\n" +
                "	text4,\n" +
                "	text5,\n" +
                "	text6,\n" +
                "	text7,\n" +
                "	text8,\n" +
                "	text9,\n" +
                "	text10,\n" +
                "	text11,\n" +
                "	text12,\n" +
                "	text13,\n" +
                "	text14,\n" +
                "	text15,\n" +
                "	text16,\n" +
                "	text18,\n" +
                "	text19,\n" +
                "	text20,\n" +
                "	text21,\n" +
                "	text22,\n" +
                "	text23,\n" +
                "	text24,\n" +
                "	text25,\n" +
                "	text26,\n" +
                "	text27,\n" +
                "	text28,\n" +
                "	text29,\n" +
                "	text30,\n" +
                "	text31,\n" +
                "	text32,\n" +
                "	text33,\n" +
                "	text34,\n" +
                "	text35,\n" +
                "	text36,\n" +
                "	text37,\n" +
                "	text38,\n" +
                "	text39,\n" +
                "	text40,\n" +
                "	text41,\n" +
                "	text42,\n" +
                "	text43,\n" +
                "	text44,\n" +
                "	text45,\n" +
                "	text46\n" +
                "FROM\n" +
                "	d_files\n" +
                "WHERE\n" +
                "	lib_id = '74'";
        return sqlRecordingLog;
    }

    public String insertTabFile2() {
        String sqlRecordingLog = "INSERT IGNORE INTO a_file_2 (\n" +
                "	id,\n" +
                "	parent_id,\n" +
                "	fix_code,\n" +
                "	region,\n" +
                "	element,\n" +
                "	time_interval,\n" +
                "	data_items,\n" +
                "	img_dataset,\n" +
                "	station,\n" +
                "	years_month,\n" +
                "	img_order,\n" +
                "	suffix,\n" +
                "	date_interval,\n" +
                "	sta_items,\n" +
                "	element1,\n" +
                "	element1_unit,\n" +
                "	element1_times,\n" +
                "	element1_items,\n" +
                "	element2,\n" +
                "	element2_unit,\n" +
                "	element2_times,\n" +
                "	element2_items,\n" +
                "	element3,\n" +
                "	element3_unit,\n" +
                "	element3_times,\n" +
                "	element3_items,\n" +
                "	element4,\n" +
                "	element4_unit,\n" +
                "	element4_times,\n" +
                "	element4_items,\n" +
                "	element5,\n" +
                "	element5_unit,\n" +
                "	element5_times,\n" +
                "	element5_items,\n" +
                "	element6,\n" +
                "	element6_unit,\n" +
                "	element6_times,\n" +
                "	element6_items,\n" +
                "	element7,\n" +
                "	element7_unit,\n" +
                "	element7_times,\n" +
                "	element7_items,\n" +
                "	element8,\n" +
                "	element8_unit,\n" +
                "	element8_times,\n" +
                "	element8_items,\n" +
                "	element9,\n" +
                "	element9_unit,\n" +
                "	element9_times,\n" +
                "	element9_items,\n" +
                "	element10,\n" +
                "	element10_unit,\n" +
                "	element10_times,\n" +
                "	element10_items,\n" +
                "	element11,\n" +
                "	element11_unit,\n" +
                "	element11_times,\n" +
                "	element11_items,\n" +
                "	element12,\n" +
                "	element12_unit,\n" +
                "	element12_times,\n" +
                "	element12_items,\n" +
                "	element13,\n" +
                "	element13_unit,\n" +
                "	element13_times,\n" +
                "	element13_items,\n" +
                "	element14,\n" +
                "	element14_unit,\n" +
                "	element14_times,\n" +
                "	element14_items,\n" +
                "	element15,\n" +
                "	element15_unit,\n" +
                "	element15_times,\n" +
                "	element15_items,\n" +
                "	element16,\n" +
                "	element16_unit,\n" +
                "	element16_times,\n" +
                "	element16_items,\n" +
                "	element17,\n" +
                "	element18,\n" +
                "	element17_unit,\n" +
                "	element18_unit,\n" +
                "	element17_times,\n" +
                "	element18_times,\n" +
                "	element17_items,\n" +
                "	element18_items,\n" +
                "	element19,\n" +
                "	element19_unit,\n" +
                "	element19_times,\n" +
                "	element19_items,\n" +
                "	element20,\n" +
                "	element20_unit,\n" +
                "	element20_times,\n" +
                "	element20_items,\n" +
                "	element21,\n" +
                "	element22,\n" +
                "	element21_unit,\n" +
                "	element22_unit,\n" +
                "	element21_times,\n" +
                "	element22_times,\n" +
                "	element21_items,\n" +
                "	element23_items,\n" +
                "	times,\n" +
                "	element23,\n" +
                "	element23_unit,\n" +
                "	element23_times,\n" +
                "	element24,\n" +
                "	element24_unit,\n" +
                "	element24_times,\n" +
                "	element24_items,\n" +
                "	element25,\n" +
                "	element25_unit,\n" +
                "	element25_times,\n" +
                "	element25_items,\n" +
                "	element22_items,\n" +
                "	element26,\n" +
                "	element26_unit,\n" +
                "	element26_times,\n" +
                "	element26_items,\n" +
                "	element27,\n" +
                "	element27_unit,\n" +
                "	element27_times,\n" +
                "	element27_items,\n" +
                "	element28,\n" +
                "	element28_unit,\n" +
                "	element28_times,\n" +
                "	element28_items,\n" +
                "	archive_code\n" +
                ") SELECT\n" +
                "	id,\n" +
                "	parent_id,\n" +
                "	text1,\n" +
                "	text2,\n" +
                "	text3,\n" +
                "	text4,\n" +
                "	text5,\n" +
                "	text6,\n" +
                "	text7,\n" +
                "	text8,\n" +
                "	text9,\n" +
                "	text10,\n" +
                "	text11,\n" +
                "	text12,\n" +
                "	text13,\n" +
                "	text14,\n" +
                "	text15,\n" +
                "	text16,\n" +
                "	text17,\n" +
                "	text18,\n" +
                "	text19,\n" +
                "	text20,\n" +
                "	text21,\n" +
                "	text22,\n" +
                "	text23,\n" +
                "	text24,\n" +
                "	text25,\n" +
                "	text26,\n" +
                "	text27,\n" +
                "	text28,\n" +
                "	text29,\n" +
                "	text30,\n" +
                "	text31,\n" +
                "	text32,\n" +
                "	text33,\n" +
                "	text34,\n" +
                "	text35,\n" +
                "	text36,\n" +
                "	text37,\n" +
                "	text38,\n" +
                "	text39,\n" +
                "	text40,\n" +
                "	text41,\n" +
                "	text42,\n" +
                "	text43,\n" +
                "	text44,\n" +
                "	text45,\n" +
                "	text46,\n" +
                "	text47,\n" +
                "	text48,\n" +
                "	text49,\n" +
                "	text50,\n" +
                "	text51,\n" +
                "	text52,\n" +
                "	text53,\n" +
                "	text54,\n" +
                "	text55,\n" +
                "	text56,\n" +
                "	text57,\n" +
                "	text58,\n" +
                "	text59,\n" +
                "	text60,\n" +
                "	text61,\n" +
                "	text62,\n" +
                "	text63,\n" +
                "	text64,\n" +
                "	text65,\n" +
                "	text66,\n" +
                "	text67,\n" +
                "	text68,\n" +
                "	text69,\n" +
                "	text70,\n" +
                "	text71,\n" +
                "	text72,\n" +
                "	text73,\n" +
                "	text74,\n" +
                "	text75,\n" +
                "	text76,\n" +
                "	text77,\n" +
                "	text78,\n" +
                "	text79,\n" +
                "	text80,\n" +
                "	text81,\n" +
                "	text82,\n" +
                "	text83,\n" +
                "	text84,\n" +
                "	text85,\n" +
                "	text86,\n" +
                "	text87,\n" +
                "	text88,\n" +
                "	text89,\n" +
                "	text90,\n" +
                "	text91,\n" +
                "	text92,\n" +
                "	text93,\n" +
                "	text94,\n" +
                "	text95,\n" +
                "	text96,\n" +
                "	text97,\n" +
                "	text98,\n" +
                "	text99,\n" +
                "	text100,\n" +
                "	text101,\n" +
                "	text102,\n" +
                "	text103,\n" +
                "	text104,\n" +
                "	text105,\n" +
                "	text106,\n" +
                "	text107,\n" +
                "	text108,\n" +
                "	text109,\n" +
                "	text110,\n" +
                "	text111,\n" +
                "	text112,\n" +
                "	text113,\n" +
                "	text114,\n" +
                "	text115,\n" +
                "	text116,\n" +
                "	text117,\n" +
                "	text118,\n" +
                "	text119,\n" +
                "	text120,\n" +
                "	text121,\n" +
                "	text122,\n" +
                "	text123,\n" +
                "	text124,\n" +
                "	text125,\n" +
                "	text140\n" +
                "FROM\n" +
                "	d_archive\n" +
                "WHERE\n" +
                "	lib_id = '75'";
        return sqlRecordingLog;
    }

    public String insertTabFile3() {
        String sqlRecordingLog = "INSERT IGNORE INTO a_file_3 (\n" +
                "	id,\n" +
                "	parent_id,\n" +
                "	fix_code,\n" +
                "	region,\n" +
                "	element,\n" +
                "	time_interval,\n" +
                "	data_items,\n" +
                "	img_dataset,\n" +
                "	station,\n" +
                "	years_month,\n" +
                "	img_order,\n" +
                "	suffix,\n" +
                "	archive_no,\n" +
                "	archive_num,\n" +
                "	register_time,\n" +
                "	district_num,\n" +
                "	classify_num,\n" +
                "	order_num,\n" +
                "	archive_name,\n" +
                "	theme_words,\n" +
                "	pro_unit,\n" +
                "	YEAR,\n" +
                "	numer,\n" +
                "	sec_class,\n" +
                "	publish_date,\n" +
                "	reten_period,\n" +
                "	loan,\n" +
                "	shelf_mark,\n" +
                "	change_content,\n" +
                "	digitalize_content,\n" +
                "	LEVEL,\n" +
                "	source,\n" +
                "	outlay,\n" +
                "	win_content,\n" +
                "	participant,\n" +
                "	remarks,\n" +
                "	archive_no1,\n" +
                "	archive_code1,\n" +
                "	volume_code,\n" +
                "	doc_code,\n" +
                "	file_name,\n" +
                "	theme_words1,\n" +
                "	pro_unit1,\n" +
                "	formation_date,\n" +
                "	num_page,\n" +
                "	change_content1,\n" +
                "	link_path,\n" +
                "	level1,\n" +
                "	remarks1,\n" +
                "	date_interval,\n" +
                "	sta_items,\n" +
                "	element1,\n" +
                "	element1_unit,\n" +
                "	element1_times,\n" +
                "	element1_items,\n" +
                "	element2,\n" +
                "	element2_unit,\n" +
                "	element2_times,\n" +
                "	element2_items,\n" +
                "	element3,\n" +
                "	element3_unit,\n" +
                "	element3_times,\n" +
                "	element3_items,\n" +
                "	element4,\n" +
                "	element4_unit,\n" +
                "	element4_times,\n" +
                "	element4_items,\n" +
                "	element5,\n" +
                "	element5_unit,\n" +
                "	element5_times,\n" +
                "	element5_items,\n" +
                "	element6,\n" +
                "	element6_unit,\n" +
                "	element6_times,\n" +
                "	element6_items,\n" +
                "	element7,\n" +
                "	element7_unit,\n" +
                "	element7_times,\n" +
                "	element7_items,\n" +
                "	element8,\n" +
                "	element8_unit,\n" +
                "	element8_times,\n" +
                "	element8_items,\n" +
                "	element9,\n" +
                "	element9_unit,\n" +
                "	element9_times,\n" +
                "	element9_items,\n" +
                "	element10,\n" +
                "	element10_unit,\n" +
                "	element10_times,\n" +
                "	element10_items,\n" +
                "	element11,\n" +
                "	element11_unit,\n" +
                "	element11_times,\n" +
                "	element11_items,\n" +
                "	element12,\n" +
                "	element12_unit,\n" +
                "	element12_times,\n" +
                "	element12_items,\n" +
                "	element13,\n" +
                "	element13_unit,\n" +
                "	element13_times,\n" +
                "	element13_items,\n" +
                "	element14,\n" +
                "	element14_unit,\n" +
                "	element14_times,\n" +
                "	element14_items,\n" +
                "	element15,\n" +
                "	element15_unit,\n" +
                "	element15_times,\n" +
                "	element15_items,\n" +
                "	element16,\n" +
                "	element17,\n" +
                "	element18,\n" +
                "	element19,\n" +
                "	element20,\n" +
                "	element16_unit,\n" +
                "	element17_unit,\n" +
                "	element18_unit,\n" +
                "	element19_unit,\n" +
                "	element20_unit,\n" +
                "	element16_times,\n" +
                "	element17_times,\n" +
                "	element18_times,\n" +
                "	element19_times,\n" +
                "	element20_times,\n" +
                "	element16_items,\n" +
                "	element17_items,\n" +
                "	element18_items,\n" +
                "	element19_items,\n" +
                "	element20_items,\n" +
                "	times\n" +
                ") SELECT\n" +
                "	id,\n" +
                "	parent_id,\n" +
                "	text1,\n" +
                "	text2,\n" +
                "	text3,\n" +
                "	text4,\n" +
                "	text5,\n" +
                "	text6,\n" +
                "	text7,\n" +
                "	text8,\n" +
                "	text9,\n" +
                "	text10,\n" +
                "	text11,\n" +
                "	text12,\n" +
                "	text13,\n" +
                "	text14,\n" +
                "	text15,\n" +
                "	text16,\n" +
                "	text18,\n" +
                "	text19,\n" +
                "	text20,\n" +
                "	text21,\n" +
                "	text22,\n" +
                "	text23,\n" +
                "	text24,\n" +
                "	text25,\n" +
                "	text26,\n" +
                "	text27,\n" +
                "	text28,\n" +
                "	text29,\n" +
                "	text30,\n" +
                "	text31,\n" +
                "	text32,\n" +
                "	text33,\n" +
                "	text34,\n" +
                "	text35,\n" +
                "	text36,\n" +
                "	text37,\n" +
                "	text39,\n" +
                "	text40,\n" +
                "	text41,\n" +
                "	text42,\n" +
                "	text43,\n" +
                "	text44,\n" +
                "	text45,\n" +
                "	text46,\n" +
                "	text47,\n" +
                "	text48,\n" +
                "	text49,\n" +
                "	text50,\n" +
                "	text51,\n" +
                "	text52,\n" +
                "	text53,\n" +
                "	text54,\n" +
                "	text55,\n" +
                "	text56,\n" +
                "	text57,\n" +
                "	text58,\n" +
                "	text59,\n" +
                "	text60,\n" +
                "	text61,\n" +
                "	text62,\n" +
                "	text63,\n" +
                "	text64,\n" +
                "	text65,\n" +
                "	text66,\n" +
                "	text67,\n" +
                "	text68,\n" +
                "	text69,\n" +
                "	text70,\n" +
                "	text71,\n" +
                "	text72,\n" +
                "	text73,\n" +
                "	text74,\n" +
                "	text75,\n" +
                "	text76,\n" +
                "	text77,\n" +
                "	text78,\n" +
                "	text79,\n" +
                "	text80,\n" +
                "	text81,\n" +
                "	text82,\n" +
                "	text83,\n" +
                "	text84,\n" +
                "	text85,\n" +
                "	text86,\n" +
                "	text87,\n" +
                "	text88,\n" +
                "	text89,\n" +
                "	text90,\n" +
                "	text91,\n" +
                "	text92,\n" +
                "	text93,\n" +
                "	text94,\n" +
                "	text95,\n" +
                "	text96,\n" +
                "	text97,\n" +
                "	text98,\n" +
                "	text99,\n" +
                "	text100,\n" +
                "	text101,\n" +
                "	text102,\n" +
                "	text103,\n" +
                "	text104,\n" +
                "	text105,\n" +
                "	text106,\n" +
                "	text107,\n" +
                "	text108,\n" +
                "	text109,\n" +
                "	text110,\n" +
                "	text111,\n" +
                "	text112,\n" +
                "	text113,\n" +
                "	text114,\n" +
                "	text115,\n" +
                "	text116,\n" +
                "	text117,\n" +
                "	text118,\n" +
                "	text119,\n" +
                "	text120,\n" +
                "	text121,\n" +
                "	text122,\n" +
                "	text123,\n" +
                "	text124,\n" +
                "	text125,\n" +
                "	text126,\n" +
                "	text127,\n" +
                "	text128,\n" +
                "	text129,\n" +
                "	text130,\n" +
                "	text131,\n" +
                "	text132\n" +
                "FROM\n" +
                "	d_archive\n" +
                "WHERE\n" +
                "	lib_id = '76'";
        return sqlRecordingLog;
    }

    public String insertTabArchive4() {
        String sqlRecordingLog = "INSERT IGNORE INTO a_archive_4 (\n" +
                "	id,\n" +
                "	station_id,\n" +
                "	fix_code,\n" +
                "	region,\n" +
                "	element,\n" +
                "	time_interval,\n" +
                "	data_items,\n" +
                "	img_dataset,\n" +
                "	station,\n" +
                "	years_month,\n" +
                "	img_order,\n" +
                "	suffix,\n" +
                "	archive_no,\n" +
                "	archive_num,\n" +
                "	register_time,\n" +
                "	district_num,\n" +
                "	classify_num,\n" +
                "	order_num,\n" +
                "	archive_name,\n" +
                "	theme_words,\n" +
                "	pro_unit,\n" +
                "	YEAR,\n" +
                "	numer,\n" +
                "	sec_class,\n" +
                "	publish_date,\n" +
                "	reten_period,\n" +
                "	loan,\n" +
                "	shelf_mark,\n" +
                "	change_content,\n" +
                "	digitalize_content,\n" +
                "	LEVEL,\n" +
                "	source,\n" +
                "	outlay,\n" +
                "	win_content,\n" +
                "	participant,\n" +
                "	remarks,\n" +
                "	archive_code1,\n" +
                "	archive_code,\n" +
                "	volume_code,\n" +
                "	doc_code,\n" +
                "	file_name,\n" +
                "	formation_date,\n" +
                "	num_page,\n" +
                "	change_content1,\n" +
                "	link_path,\n" +
                "	level1,\n" +
                "	remarks1\n" +
                ") SELECT\n" +
                "	id,\n" +
                "	station_id,\n" +
                "	text1,\n" +
                "	text2,\n" +
                "	text3,\n" +
                "	text4,\n" +
                "	text5,\n" +
                "	text6,\n" +
                "	text7,\n" +
                "	text8,\n" +
                "	text9,\n" +
                "	text10,\n" +
                "	text11,\n" +
                "	text12,\n" +
                "	text13,\n" +
                "	text14,\n" +
                "	text15,\n" +
                "	text16,\n" +
                "	text18,\n" +
                "	text19,\n" +
                "	text20,\n" +
                "	text21,\n" +
                "	text22,\n" +
                "	text23,\n" +
                "	text24,\n" +
                "	text25,\n" +
                "	text26,\n" +
                "	text27,\n" +
                "	text28,\n" +
                "	text29,\n" +
                "	text30,\n" +
                "	text31,\n" +
                "	text32,\n" +
                "	text33,\n" +
                "	text34,\n" +
                "	text35,\n" +
                "	text36,\n" +
                "	text37,\n" +
                "	text38,\n" +
                "	text39,\n" +
                "	text40,\n" +
                "	text41,\n" +
                "	text42,\n" +
                "	text43,\n" +
                "	text44,\n" +
                "	text45,\n" +
                "	text46\n" +
                "FROM\n" +
                "	d_files\n" +
                "WHERE\n" +
                "	lib_id = '89'";
        return sqlRecordingLog;
    }

    public String insertTabFile4() {
        String sqlRecordingLog = "INSERT IGNORE INTO a_file_4 (\n" +
                "	id,\n" +
                "	parent_id,\n" +
                "	fix_code,\n" +
                "	region,\n" +
                "	element,\n" +
                "	time_interval,\n" +
                "	data_items,\n" +
                "	img_dataset,\n" +
                "	station,\n" +
                "	years_month,\n" +
                "	img_order,\n" +
                "	suffix,\n" +
                "	date_interval,\n" +
                "	sta_items,\n" +
                "	element1,\n" +
                "	element1_unit,\n" +
                "	element1_times,\n" +
                "	element1_items,\n" +
                "	element2,\n" +
                "	element2_unit,\n" +
                "	element2_times,\n" +
                "	element2_items,\n" +
                "	element3,\n" +
                "	element3_unit,\n" +
                "	element3_times,\n" +
                "	element3_items,\n" +
                "	element4,\n" +
                "	element4_unit,\n" +
                "	element4_times,\n" +
                "	element4_items,\n" +
                "	element5,\n" +
                "	element5_unit,\n" +
                "	element5_times,\n" +
                "	element5_items,\n" +
                "	element6,\n" +
                "	element6_unit,\n" +
                "	element6_times,\n" +
                "	element6_items,\n" +
                "	element7,\n" +
                "	element7_unit,\n" +
                "	element7_times,\n" +
                "	element7_items,\n" +
                "	element8,\n" +
                "	element8_unit,\n" +
                "	element8_times,\n" +
                "	element8_items,\n" +
                "	element9,\n" +
                "	element9_unit,\n" +
                "	element9_times,\n" +
                "	element9_items,\n" +
                "	element10,\n" +
                "	element10_unit,\n" +
                "	element10_times,\n" +
                "	element10_items,\n" +
                "	element11,\n" +
                "	element11_unit,\n" +
                "	element11_times,\n" +
                "	element11_items,\n" +
                "	element12,\n" +
                "	element12_unit,\n" +
                "	element12_times,\n" +
                "	element12_items,\n" +
                "	element13,\n" +
                "	element13_unit,\n" +
                "	element13_times,\n" +
                "	element13_items,\n" +
                "	element14,\n" +
                "	element14_unit,\n" +
                "	element14_times,\n" +
                "	element14_items,\n" +
                "	element15,\n" +
                "	element15_unit,\n" +
                "	element15_times,\n" +
                "	element15_items,\n" +
                "	element16,\n" +
                "	element16_unit,\n" +
                "	element16_times,\n" +
                "	element16_items,\n" +
                "	element17,\n" +
                "	element18,\n" +
                "	element17_unit,\n" +
                "	element18_unit,\n" +
                "	element17_times,\n" +
                "	element18_times,\n" +
                "	element17_items,\n" +
                "	element18_items,\n" +
                "	element19,\n" +
                "	element19_unit,\n" +
                "	element19_times,\n" +
                "	element19_items,\n" +
                "	element20,\n" +
                "	element20_unit,\n" +
                "	element20_times,\n" +
                "	element20_items,\n" +
                "	element21,\n" +
                "	element22,\n" +
                "	element21_unit,\n" +
                "	element22_unit,\n" +
                "	element21_times,\n" +
                "	element22_times,\n" +
                "	element21_items,\n" +
                "	element23_items,\n" +
                "	times,\n" +
                "	element23,\n" +
                "	element23_unit,\n" +
                "	element23_times,\n" +
                "	element24,\n" +
                "	element24_unit,\n" +
                "	element24_times,\n" +
                "	element24_items,\n" +
                "	element25,\n" +
                "	element25_unit,\n" +
                "	element25_times,\n" +
                "	element25_items,\n" +
                "	element22_items,\n" +
                "	element26,\n" +
                "	element26_unit,\n" +
                "	element26_times,\n" +
                "	element26_items,\n" +
                "	element27,\n" +
                "	element27_unit,\n" +
                "	element27_times,\n" +
                "	element27_items,\n" +
                "	element28,\n" +
                "	element28_unit,\n" +
                "	element28_times,\n" +
                "	element28_items,\n" +
                "	archive_code\n" +
                ") SELECT\n" +
                "	id,\n" +
                "	parent_id,\n" +
                "	text1,\n" +
                "	text2,\n" +
                "	text3,\n" +
                "	text4,\n" +
                "	text5,\n" +
                "	text6,\n" +
                "	text7,\n" +
                "	text8,\n" +
                "	text9,\n" +
                "	text10,\n" +
                "	text11,\n" +
                "	text12,\n" +
                "	text13,\n" +
                "	text14,\n" +
                "	text15,\n" +
                "	text16,\n" +
                "	text17,\n" +
                "	text18,\n" +
                "	text19,\n" +
                "	text20,\n" +
                "	text21,\n" +
                "	text22,\n" +
                "	text23,\n" +
                "	text24,\n" +
                "	text25,\n" +
                "	text26,\n" +
                "	text27,\n" +
                "	text28,\n" +
                "	text29,\n" +
                "	text30,\n" +
                "	text31,\n" +
                "	text32,\n" +
                "	text33,\n" +
                "	text34,\n" +
                "	text35,\n" +
                "	text36,\n" +
                "	text37,\n" +
                "	text38,\n" +
                "	text39,\n" +
                "	text40,\n" +
                "	text41,\n" +
                "	text42,\n" +
                "	text43,\n" +
                "	text44,\n" +
                "	text45,\n" +
                "	text46,\n" +
                "	text47,\n" +
                "	text48,\n" +
                "	text49,\n" +
                "	text50,\n" +
                "	text51,\n" +
                "	text52,\n" +
                "	text53,\n" +
                "	text54,\n" +
                "	text55,\n" +
                "	text56,\n" +
                "	text57,\n" +
                "	text58,\n" +
                "	text59,\n" +
                "	text60,\n" +
                "	text61,\n" +
                "	text62,\n" +
                "	text63,\n" +
                "	text64,\n" +
                "	text65,\n" +
                "	text66,\n" +
                "	text67,\n" +
                "	text68,\n" +
                "	text69,\n" +
                "	text70,\n" +
                "	text71,\n" +
                "	text72,\n" +
                "	text73,\n" +
                "	text74,\n" +
                "	text75,\n" +
                "	text76,\n" +
                "	text77,\n" +
                "	text78,\n" +
                "	text79,\n" +
                "	text80,\n" +
                "	text81,\n" +
                "	text82,\n" +
                "	text83,\n" +
                "	text84,\n" +
                "	text85,\n" +
                "	text86,\n" +
                "	text87,\n" +
                "	text88,\n" +
                "	text89,\n" +
                "	text90,\n" +
                "	text91,\n" +
                "	text92,\n" +
                "	text93,\n" +
                "	text94,\n" +
                "	text95,\n" +
                "	text96,\n" +
                "	text97,\n" +
                "	text98,\n" +
                "	text99,\n" +
                "	text100,\n" +
                "	text101,\n" +
                "	text102,\n" +
                "	text103,\n" +
                "	text104,\n" +
                "	text105,\n" +
                "	text106,\n" +
                "	text107,\n" +
                "	text108,\n" +
                "	text109,\n" +
                "	text110,\n" +
                "	text111,\n" +
                "	text112,\n" +
                "	text113,\n" +
                "	text114,\n" +
                "	text115,\n" +
                "	text116,\n" +
                "	text117,\n" +
                "	text118,\n" +
                "	text119,\n" +
                "	text120,\n" +
                "	text121,\n" +
                "	text122,\n" +
                "	text123,\n" +
                "	text124,\n" +
                "	text125,\n" +
                "	text140\n" +
                "FROM\n" +
                "	d_archive\n" +
                "WHERE\n" +
                "	lib_id = '90'";
        return sqlRecordingLog;
    }


}
